//
//  ShopDetailViewController.m
//  Socrates
//
//  Created by shy on 15/4/8.
//  Copyright (c) 2015年 shy. All rights reserved.
//

#import "ShopDetailViewController.h"

#import "CircleImage.h"
#import "ImageGallery.h"
#import "RDVTabBarController.h"
#import "ShopInfoViewController.h"

typedef enum {
    kActivity_time_item = 0,
    kActivity_location_item,
    kActivity_fee_item,
    kActivity_activity_hint_item,
    kActivity_Num,
} ActivityItems;

typedef enum {
    kActivity_information_section = 0,
    kActivity_comment_section,
    kActivity_Section_Nums,
} ActivitySections;

typedef enum {
    kActivity_information_section_row_num = 0,
    kActivity_comment_section_row_num,
    kActivity_Section_row_Nums,
} ActivitySectionRowNums;

static const int kLimitationRowHeight = 40.;

@implementation ShopDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configGallaryView];
    [self configOwnerView];
    self.navigationItem.title = @"商家详情";
    self.tableView.scrollEnabled = NO;
}

- (void)configGallaryView {
    NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"prefer_test_shop"],[UIImage imageNamed:@"user_info_bg"],[UIImage imageNamed:@"home_test_activity"], nil];
    ImageGallery *imageGallery = [[ImageGallery alloc] initWithImages:images];
    [self.gallaryView addSubview:imageGallery];
}

- (void)configOwnerView {
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGSize ownerSize = CGSizeMake([UIScreen mainScreen] .bounds.size.width, self.ownerView.frame.size.height);
    CGSize userSize = CGSizeMake(60, 60);
    CGFloat topEdge = 10.;
    CGFloat separateEdge = 6;
    CGFloat labelHeight = 15;
    CGFloat labelAEdge = userSize.width + 15 + 5;
//    CGFloat labelBEdge = labelAEdge + 0.23*width + 15;
    self.shop = [[UIButton alloc] initWithFrame:CGRectMake(15, (ownerSize.height - userSize.height)/2, userSize.width, userSize.height)];
    UIImage *shopImage = [CircleImage circleImageWithName:@"angela_test" borderWidth:0 borderColor:[UIColor clearColor]];
    [self.shop setImage:shopImage forState:UIControlStateNormal];
    [self.shop addTarget:self action:@selector(clickShop:) forControlEvents:UIControlEventTouchUpInside];
    [self.ownerView addSubview:self.shop];

    self.shopName = [[UILabel alloc] initWithFrame:CGRectMake(labelAEdge, topEdge, 0.46*width, labelHeight)];
//        self.shopName.backgroundColor = [UIColor purpleColor];
    self.shopName.textColor = [UIColor blackColor];
    self.shopName.font = [UIFont systemFontOfSize:13.];
    self.shopName.text = @"必胜客学院路店";
    [self.ownerView addSubview:self.shopName];
    
    self.shopLocation = [[UILabel alloc] initWithFrame:CGRectMake(labelAEdge, topEdge + labelHeight + separateEdge, 0.46*width, labelHeight)];
//    self.shopLocation.backgroundColor = [UIColor purpleColor];
    self.shopLocation.textColor = [UIColor grayColor];
    self.shopLocation.font = [UIFont systemFontOfSize:13.];
    self.shopLocation.text = @"北京市 朝阳区 学院路 108号";
    [self.ownerView addSubview:self.shopLocation];

    self.shopType = [[UILabel alloc] initWithFrame:CGRectMake(labelAEdge, topEdge + labelHeight*2 + separateEdge*2, 0.46*width, labelHeight)];
//    self.shopType.backgroundColor = [UIColor purpleColor];
    self.shopType.textColor = [UIColor grayColor];
    self.shopType.font = [UIFont systemFontOfSize:13.];
    self.shopType.text = @"必胜客茶餐厅";
    [self.ownerView addSubview:self.shopType];
    
    UIImageView *heart = [[UIImageView alloc] initWithFrame:CGRectMake(width - 50, 20, 25, 20)];
    heart.image = [UIImage imageNamed:@"home_like"];
    [self.ownerView addSubview:heart];
    
    self.likes = [[UILabel alloc] initWithFrame:CGRectMake(width - 50, 40, 30, labelHeight)];
    //    self.likes.backgroundColor = [UIColor purpleColor];
    self.likes.textColor = [UIColor grayColor];
    self.likes.font = [UIFont systemFontOfSize:13.];
    self.likes.text = @"23";
    self.likes.textAlignment = NSTextAlignmentCenter;
    [self.ownerView addSubview:self.likes];

}

- (void)clickShop: (id)sender {
    ShopInfoViewController *vc = [[ShopInfoViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    switch (section) {
        case kActivity_information_section:
            return 80;
            break;
        case kActivity_comment_section:
            return 30;
            break;
        default:
            break;
    }
    return 0;
}

- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];
    viewA.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    UILabel *hintA = [[UILabel alloc] initWithFrame:CGRectMake(23, 0, [UIScreen mainScreen].bounds.size.width - 46, 40)];
    hintA.textColor = [UIColor blackColor];
    hintA.text = @"周杰伦2015演唱会随行小伙伴";
    hintA.font = [UIFont systemFontOfSize:16.];
    [viewA addSubview:hintA];
    UILabel *hintAA = [[UILabel alloc] initWithFrame:CGRectMake(23, 40, [UIScreen mainScreen].bounds.size.width - 46, 40)];
    hintAA.textColor = [UIColor grayColor];
    hintAA.text = @"发布此活动邀请趣友参加，组队成功后可凭识趣儿推送的验证码享受一定的优惠";
    hintAA.font = [UIFont systemFontOfSize:13];
    hintAA.numberOfLines = 2;
    [viewA addSubview:hintAA];
    
    UIView *viewB = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
    viewB.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    UILabel *hintB = [[UILabel alloc] initWithFrame:CGRectMake(23, 0, [UIScreen mainScreen].bounds.size.width - 46, 30)];
    hintB.textColor = [UIColor grayColor];
    hintB.text = @"评论";
    hintB.font = [UIFont systemFontOfSize:14.];
    [viewB addSubview:hintB];
    switch (section) {
        case kActivity_information_section:
            return viewA;
        case kActivity_comment_section:
            return viewB;
            break;
        default:
            break;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row] == kActivity_activity_hint_item) {
        return 60;
    } else {
        return kLimitationRowHeight;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return kActivity_Section_Nums;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case kActivity_information_section_row_num:
            return kActivity_Num;
            break;
        case kActivity_comment_section_row_num:
            return 2;
        default:
            break;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = @"HomeCellIdentifier";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    UIImageView *time = [[UIImageView alloc] initWithFrame:CGRectMake(23, 10, 20, 20)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, [UIScreen mainScreen].bounds.size.width - 80, 40)];
    label.textColor = [UIColor grayColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:15.];
    switch ([indexPath section]) {
        case kActivity_information_section:
            switch ([indexPath row]) {
                case kActivity_time_item:
                    time.image = [UIImage imageNamed:@"home_time"];
                    [cell addSubview:time];
                    label.text = @"2015/11/28/19:00-2015/12/30/19:00";
                    [cell addSubview:label];
                    break;
                case kActivity_location_item:
                    time.image = [UIImage imageNamed:@"home_location"];
                    [cell addSubview:time];
                    label.text = @"鸟巢体育馆";
                    [cell addSubview:label];
                    break;
                case kActivity_fee_item:
                    time.image = [UIImage imageNamed:@"home_fee"];
                    [cell addSubview:time];
                    label.text = @"288元/人";
                    [cell addSubview:label];
                    break;
                case kActivity_activity_hint_item:
                    cell.textLabel.text = @"周杰伦演唱会，真情邀请杰迷朋友一起来祝福，地点：鸟巢，水立方集合，希望准时";
                    cell.textLabel.textColor = [UIColor grayColor];
                    cell.textLabel.font = [UIFont systemFontOfSize:15.];
                    break;
                default:
                    break;
            }
            break;
        case kActivity_comment_section:
            
            break;
        default:
            break;
    }
    return cell;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.scrollView setContentSize:CGSizeMake(320,700)];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}

@end

